<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>e网批发管理后台</title>
<?php include("common/conn.php");
include("./tool/UpFileTool.class.php");
$rert37=mysql_query("select * from goods  where  goodsid='".$_REQUEST[id]."' ");

$sdg37=mysql_fetch_array($rert37);

//更改主图
if($_GET['doDefaultImg']=="ok")//删除图片
{
   $query = mysql_query("UPDATE goods set defaultXQTuOrd='".$_REQUEST[defaultXQTuOrd]."' where goodsid=".$_REQUEST['id']);
   if($query){
   	  echo '1';
   }else{
   	  echo '2';
   }
}

if($_GET['del']=="ok")//删除图片
{
	$due=','.$_REQUEST[img];
	       if(strstr($sdg37[xiangQingTu],$due)!=false)
	       {
	           $xiangQingTu2=str_replace($due,'',$sdg37[xiangQingTu]);
	    
			}else
			
			{
				    if (strstr($sdg37[xiangQingTu],',')!=false) {
				        $dues=$_REQUEST[img].',';
				        $xiangQingTu2=str_replace($dues,'',$sdg37[xiangQingTu]);
				    }else{
				        $dues=$_REQUEST[img];
				        $xiangQingTu2=str_replace($dues,'',$sdg37[xiangQingTu]);
		    }
		
		}

	$srat1=mysql_query("update goods set xiangQingTu='".$xiangQingTu2."' where goodsid='".$_REQUEST['id']."'");
	echo "<script>window.location.href='addgoodsXiangQingTu.php?id=".$_REQUEST['id']."'</script>";
}


if($_GET['action']=="ok"){
	$query=mysql_query("select * from goods where goodsid='".$_REQUEST['id']."'");
	$goods=mysql_fetch_assoc($query);

	if ($_FILES) {
		$UpFileTool = new UpFileTool('file');
		$xiangQingTu=$UpFileTool->multiSrcImage;
		if ($goods[xiangQingTu]!='') {
			$xiangQingTu=$goods[xiangQingTu].','.$xiangQingTu;
		}
	
		$srat1=mysql_query("update goods set xiangQingTu='".$xiangQingTu."' where goodsid='".$_REQUEST['id']."'");
	}
	
	echo "<script>window.location.href='addgoodsXiangQingTu.php?id=".$_REQUEST['id']."'</script>";
}

?>
<script type="text/javascript" src="js/jquery.min.js"></script>

    <!-- MASTER STYLESHEET-->
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
    
    <!-- LOAD TIPSY TOOLTIPS-->
    <script type="text/javascript" src="js/jquery.tipsy.js"></script>
   
    <!-- LOAD CUSTOM JQUERY SCRIPTS-->
    <script type="text/javascript" src="js/scripts.js"></script>	
    
	 <!-- LOAD FACEBOX -->
	<script type="text/javascript" src="js/facebox.js"></script>
    <link href="css/facebox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery.flot.pack.js"></script>
	<script src="js/graphs.js" type="text/javascript"></script>


</head>

<body>
    <!--header-->
    <?php include("common/header.php");?>
    <!--header end-->


<!-- staqrt subnav -->
<div id="sub_nav">

<div id="subnav_wrap" class="container_12">
	
    <!-- start sub nav list -->
	<div id="subnav" class=" grid_12">
    
        <ul>
          
		  <li><a href="addgoodsimg.php?id=<?php echo $_REQUEST[id];?>" >主图管理</a></li>
		  <li><a href="addgoodsXiangQingTu.php?id=<?php echo $_REQUEST[id];?>"  class="sub_nav_active">详情图管理</a></li>
		</ul>
    
    </div>
    <!-- end subnavigation list -->	

</div>


</div>
<!-- end sub_nav -->

<!-- EVERYTING BELOW IS THE MAIN CONTENT -->

<div class="container_12">
<form action="?action=ok&id=<?php echo $_REQUEST[id];?>" method="post" enctype="multipart/form-data">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
	  
            <tr>
            <th width="30%" scope="col">上传商品详情图
               <span style="font-size: 8px;font-weight: normal;">（单张/多张上传)
               </span>
            </th>
			<th width="50%" scope="col"><input name="file[]" type="file"  multiple="multiple"/></th>
			<th width="20%" scope="col"><input  type="submit" value="上传" /></th>
			</tr>
	<?php 
			$rert37=mysql_query("select * from goods  where  goodsid='".$_REQUEST[id]."' ");

	        $sdg37=mysql_fetch_array($rert37);

			$ime=$sdg37[xiangQingTu];
			$de = array();
			$de=explode("," ,$ime);
		  foreach($de as $key => $tmp_name ) { if($tmp_name!=""){?>	
			<tr>

            <th width="25%" scope="col"><?php echo $sdg37[id];?></th>
            
            <th width="50%" scope="col">
                <span style="color: red;">(点击置顶)</span>
				<input  onclick="doDefaultImg('<?php echo $key; ?>');"  type="radio" name="defaultXQTuOrd" value="<?php echo $key; ?>" <?php if ($key == $sdg37[defaultXQTuOrd] || $key == 0) { ?> checked="checked"   <?php } ?>>
				<img src="<?php echo $tmp_name;?>" style="height:100px; width:100px;" />
			</th>

			<th width="20%" scope="col">
				<div class="youse">
					<a href="?id=<?php echo $_REQUEST[id];?>&del=ok&img=<?php echo $tmp_name;?>">删除
					</a>
				</div>
			</th>
			</tr>
		
             <?php }}?>
     
		
    </table>
    </form>
    <!-- END TABULAR DATA EXAMPLE -->
           
</div>
          
          
</div>

<!-- end content wrap -->

</body>
<script type="text/javascript">
	 function doDefaultImg(key){
		  $.get("?id=<?php echo $_REQUEST[id];?>&doDefaultImg=ok&defaultXQTuOrd="+key,function(data,status){
		        if(data){
		          alert('设置成功');	
		        }else{
		        	alert('设置失败');	
		        }
		  });
	     }
</script>
</html>
